<template>
	<view>
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30 u-p-t-30">
			<view class="u-m-r-10">
				<u-avatar v-if="user.picture" :src="user.picture" size="110"></u-avatar>
				<u-avatar v-else src="/static/user.jpg" size="110"></u-avatar>
			</view>
			<view @click="toInfo" class="u-flex-1">
				<view class="u-font-15 u-p-b-20">{{user.nickName}}</view>
				<view class="u-font-14 u-tips-color">{{user.phone}}</view>
			</view>
			<view class="u-m-l-10 u-p-10">
				<u-icon name="arrow-right" color="#969799" size="28"></u-icon>
			</view>
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item @click="myFind" icon="star" title="我的寻物"></u-cell-item>
				<u-cell-item @click="myClaim" icon="photo" title="我的招领"></u-cell-item>
				<u-cell-item @click="myCollect" icon="photo" title="我的收藏"></u-cell-item>
				<u-cell-item @click="updateBtn" icon="coupon" title="修改密码"></u-cell-item>
				<u-cell-item @click="toLogin" icon="heart" title="退出登录"></u-cell-item>
			</u-cell-group>
		</view>
	
	</view>
</template>

<script setup>
	import {reactive} from 'vue'
import { onShow } from '@dcloudio/uni-app';
import {getInfoApi} from '../../src/api/user.js'
//我的寻物
const myFind = ()=>{
	uni.navigateTo({
		url:'../my_find/my_find'
	})
}
//我的招领
const myClaim = ()=>{
	uni.navigateTo({
		url:'../my_claim/my_claim'
	})
}
//我的收藏
const myCollect = ()=>{
	uni.navigateTo({
		url:'../my_collect/my_collect'
	})
}
//修改密码
const updateBtn = ()=>{
	uni.navigateTo({
		url:'../update_password/update_password'
	})
}
//意见反馈

//用户信息
let user = reactive({});
//修改个人信息
const toInfo = ()=>{
	uni.navigateTo({
		url:'../user_info/user_info?user='+JSON.stringify(user)
	})
}
//退出登录
const toLogin = ()=>{
	//清空缓存
	uni.clearStorage()
	//跳转登录
	uni.reLaunch({
		url:"../login/login"
	})
}

//获取用户信息
const getInfo = async()=>{
	let res = await getInfoApi({
		userId:uni.getStorageSync("userId")
	})
	if(res && res.code == 200){
		console.log(res)
		Object.assign(user,res.data)
	}
}
onShow(()=>{
	getInfo()
})
</script>

<style lang="scss">
page{
	background-color: #ededed;
}

.camera{
	width: 54px;
	height: 44px;
	
	&:active{
		background-color: #ededed;
	}
}
.user-box{
	background-color: #fff;
}
</style>